<template>
  <div class="settings-container">
    <el-card class="settings-card">
      <template #header>
        <div class="card-header">
          <h2>系统信息</h2>
        </div>
      </template>

      <div class="about-system">
        <div class="system-logo">
          <img src="../assets/logo.png" alt="系统Logo" />
        </div>
        <h3 class="system-name">电缆管理系统</h3>
        <div class="system-version">版本: v1.0.0</div>
        <div class="system-description">
          本系统是一个专业的电缆管理平台，提供广告管理、库存管理、用户管理等功能，
          帮助企业高效管理业务流程，提升运营效率。
        </div>
        
        <el-divider />
        
        <h4>系统架构</h4>
        <el-descriptions :column="1" border>
          <el-descriptions-item label="前端框架">Vue 3 + Element Plus</el-descriptions-item>
          <el-descriptions-item label="后端框架">NestJS</el-descriptions-item>
          <el-descriptions-item label="数据库">腾讯云 MySQL 5.7</el-descriptions-item>
          <el-descriptions-item label="ORM框架">TypeORM</el-descriptions-item>
          <el-descriptions-item label="服务器">腾讯云服务器</el-descriptions-item>
          <el-descriptions-item label="对象存储">腾讯云对象存储 COS</el-descriptions-item>
        </el-descriptions>
        
        <el-divider />
        
        <h4>运行环境</h4>
        <el-descriptions :column="1" border>
          <el-descriptions-item label="浏览器">{{ browserInfo }}</el-descriptions-item>
          <el-descriptions-item label="操作系统">{{ osInfo }}</el-descriptions-item>
          <el-descriptions-item label="屏幕分辨率">{{ screenInfo }}</el-descriptions-item>
          <el-descriptions-item label="当前语言">{{ languageInfo }}</el-descriptions-item>
          <el-descriptions-item label="Node.js版本">v16.14.0</el-descriptions-item>
        </el-descriptions>
        
        <el-divider />
        
        <h4>系统性能</h4>
        <el-descriptions :column="1" border>
          <el-descriptions-item label="API平均响应时间">120ms</el-descriptions-item>
          <el-descriptions-item label="系统运行时间">{{ uptime }}</el-descriptions-item>
          <el-descriptions-item label="服务器配置">腾讯云服务器 2核4G内存 6M带宽</el-descriptions-item>
          <el-descriptions-item label="数据库配置">腾讯云MySQL 5.7 2核4G内存 20G存储</el-descriptions-item>
          <el-descriptions-item label="对象存储配置">腾讯云COS 标准存储 500G</el-descriptions-item>
          <el-descriptions-item label="数据库连接池">最大连接数: 50</el-descriptions-item>
          <el-descriptions-item label="缓存机制">Redis</el-descriptions-item>
        </el-descriptions>
        
        <el-divider />
        
        <h4>开发团队</h4>
        <div class="team-info">
          <p>本系统由XXX团队开发完成</p>
          <p>联系邮箱: support@example.com</p>
          <p>技术支持: 400-123-4567</p>
        </div>
        
        <el-divider />
        
        <div class="copyright">
          © {{ currentYear }} 电缆管理系统 版权所有
        </div>
      </div>
    </el-card>
  </div>
</template>

<script setup>
import { ref, computed, onMounted } from 'vue'

// 系统信息
const browserInfo = computed(() => {
  const ua = navigator.userAgent
  let browserName = "未知浏览器"
  
  if (ua.indexOf("Firefox") > -1) {
    browserName = "Firefox"
  } else if (ua.indexOf("Chrome") > -1 && ua.indexOf("Edge") === -1 && ua.indexOf("Edg") === -1) {
    browserName = "Chrome"
  } else if (ua.indexOf("Edge") > -1 || ua.indexOf("Edg") > -1) {
    browserName = "Edge"
  } else if (ua.indexOf("Safari") > -1 && ua.indexOf("Chrome") === -1) {
    browserName = "Safari"
  } else if (ua.indexOf("MSIE") > -1 || ua.indexOf("Trident") > -1) {
    browserName = "Internet Explorer"
  }
  
  return `${browserName} ${navigator.appVersion.split(' ').pop()}`
})

const osInfo = computed(() => {
  const ua = navigator.userAgent
  let os = "未知系统"
  
  if (ua.indexOf("Win") > -1) {
    os = "Windows"
  } else if (ua.indexOf("Mac") > -1) {
    os = "MacOS"
  } else if (ua.indexOf("Linux") > -1) {
    os = "Linux"
  } else if (ua.indexOf("Android") > -1) {
    os = "Android"
  } else if (ua.indexOf("iPhone") > -1 || ua.indexOf("iPad") > -1) {
    os = "iOS"
  }
  
  return os
})

const screenInfo = computed(() => {
  return `${window.screen.width} x ${window.screen.height}`
})

const languageInfo = computed(() => {
  return navigator.language || navigator.userLanguage
})

const currentYear = computed(() => {
  return new Date().getFullYear()
})

// 系统运行时间
const uptime = ref('0天 0小时 0分钟')

// 计算系统运行时间
const calculateUptime = () => {
  // 模拟系统启动时间，实际项目中可以从后端获取
  const startTime = new Date('2023-05-01T00:00:00')
  const now = new Date()
  const diff = now - startTime
  
  const days = Math.floor(diff / (1000 * 60 * 60 * 24))
  const hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60))
  const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60))
  
  uptime.value = `${days}天 ${hours}小时 ${minutes}分钟`
}

// 初始化
onMounted(() => {
  calculateUptime()
  // 每分钟更新一次运行时间
  setInterval(calculateUptime, 60000)
})
</script>

<style scoped>
.settings-container {
  padding: 20px;
}

.settings-card {
  margin-bottom: 20px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-header h2 {
  margin: 0;
  font-size: 1.5rem;
  color: #303133;
}

.about-system {
  text-align: center;
  padding: 20px;
}

.system-logo {
  margin-bottom: 20px;
}

.system-logo img {
  max-width: 200px;
  height: auto;
}

.system-name {
  font-size: 24px;
  margin-bottom: 10px;
}

.system-version {
  color: #909399;
  margin-bottom: 20px;
}

.system-description {
  color: #606266;
  max-width: 600px;
  margin: 0 auto 30px;
  line-height: 1.6;
}

.team-info {
  color: #606266;
  margin: 20px 0;
}

.copyright {
  color: #909399;
  font-size: 14px;
  margin-top: 30px;
}

:deep(.el-descriptions) {
  max-width: 800px;
  margin: 0 auto;
  text-align: left;
}

:deep(.el-descriptions__label) {
  width: 150px;
  font-weight: bold;
}

h4 {
  margin: 20px 0;
  font-size: 18px;
  color: #303133;
}

.el-divider {
  margin: 30px 0;
}
</style>